@Inject('$log', '$rootScope', '$state', 'noticeService', 'ngDialogService')
class AddNoticeController {
  constructor() {
    this.announcementInfo = {
      title: '',
      context: '',
      attachmentIds: [],
      unit: '1',
    };
    this.view = {
      files: [],
    };
  }

  $saveInfo() {
    this.announcementInfo.attachmentIds = this.view.files.map(item => item.id);
    this.noticeService
      .save(this.announcementInfo)
      .then((res) => {
        if (res.success) {
          this.ngDialogService.alertSuccess(res.message);
          this.$state.go('noticeDetail', { id: res.data.id });
        } else {
          this.ngDialogService.alertError(res.message);
        }
      });
  }
}

export default AddNoticeController;
